package com.serviceImpl;

import com.javabean.Permission;
import com.mapper.PermissionMapper;
import com.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @Author: 张波
 * @Time: 2025/8/28 14:44
 */
@Service
public class PermissionServiceImpl implements PermissionService {
	private final PermissionMapper permissionMapper;

	public PermissionServiceImpl(PermissionMapper permissionMapper) {
		this.permissionMapper = permissionMapper;
	}

	/**
	 *
	 * @return 权限查询对象
	 */
	@Override
	public List<Permission> findAll() {
		return permissionMapper.selectAll();
	}

	/**
	 *
	 * @param permissionName 权限名称
	 * @param url  权限
	 * @return 受影响的行数
	 */
	@Override
	public void addPermission(String permissionName, String url) {
		 permissionMapper.insertPermission(permissionName, url);
	}

	/**
	 *
	 * @param id 查询id
	 * @return 返回Permission对象
	 */
	@Override
	public Permission findById(int id) {
		return permissionMapper.selectById(id);
	}

	/**
	 *
	 * @param permission 传入权限对象
	 */
	@Override
	public void updatePermission(Permission permission) {
		 permissionMapper.updateOneById(permission);
	}

	/**
	 *
	 * @param id 传入被删除的对象的id
	 */
	@Override
	public void deletePermission(int id) {
		permissionMapper.deleteById(id);
	}

	/**
	 *
	 * @param rid 传入角色的id
	 * @return 返回权限的集合
	 */
	@Override
	public List<Permission> findByRid(int rid) {
		return permissionMapper.selectByRid(rid);
	}


}
